package com.xinqi.modules.chat.chat.official.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xinqi.common.base.enums.YesNoNumberEnum;
import com.xinqi.common.core.constant.ChatRemindConstants;
import com.xinqi.common.core.enums.AssistantMesTypeEnum;
import com.xinqi.common.core.enums.AssistantMessageTypeEnum;
import com.xinqi.common.core.enums.AssistantTypeEnum;
import com.xinqi.common.core.enums.ClassRoleEnum;
import com.xinqi.common.mybatis.data.service.impl.BaseServiceImpl;
import com.xinqi.common.mybatis.utils.Queries;
import com.xinqi.modules.chat.chat.friend.domain.ChatFriendEntity;
import com.xinqi.modules.chat.chat.friend.manager.ChatFriendManager;
import com.xinqi.modules.chat.chat.official.convert.ChatAssistantContentCovert;
import com.xinqi.modules.chat.chat.official.domain.ChatAssistantConfigEntity;
import com.xinqi.modules.chat.chat.official.domain.ChatAssistantContentEntity;
import com.xinqi.modules.chat.chat.official.dto.AssistantIdDTO;
import com.xinqi.modules.chat.chat.official.dto.req.ChatAssistantContentCreateDTO;
import com.xinqi.modules.chat.chat.official.dto.req.ChatAssistantContentMainDTO;
import com.xinqi.modules.chat.chat.official.dto.req.ChatAssistantContentTotalDTO;
import com.xinqi.modules.chat.chat.official.dto.req.ChatAssistantContentUpdateDTO;
import com.xinqi.modules.chat.chat.official.dto.rsp.ChatAssistantContentMessageResultDTO;
import com.xinqi.modules.chat.chat.official.json.AttendanceMessage;
import com.xinqi.modules.chat.chat.official.json.CourseWareMessage;
import com.xinqi.modules.chat.chat.official.json.EvaluationMessage;
import com.xinqi.modules.chat.chat.official.json.HomeWorkMessage;
import com.xinqi.modules.chat.chat.official.json.NoticeMessage;
import com.xinqi.modules.chat.chat.official.json.VideoMessage;
import com.xinqi.modules.chat.chat.official.manager.ChatAssistantConfigManager;
import com.xinqi.modules.chat.chat.official.mapper.ChatAssistantContentMapper;
import com.xinqi.modules.chat.chat.official.service.ChatAssistantContentService;
import com.xinqi.modules.chat.favorite.controller.web.utils.JSONUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import java.util.stream.Collectors;

import static com.xinqi.common.core.enums.AssistantMessageTypeEnum.ATTENDANCE;
import static com.xinqi.common.core.enums.AssistantMessageTypeEnum.COURSEWARE;
import static com.xinqi.common.core.enums.AssistantMessageTypeEnum.DATA;
import static com.xinqi.common.core.enums.AssistantMessageTypeEnum.DISCUSS;
import static com.xinqi.common.core.enums.AssistantMessageTypeEnum.EXAM;
import static com.xinqi.common.core.enums.AssistantMessageTypeEnum.HOMEWORK;
import static com.xinqi.common.core.enums.AssistantMessageTypeEnum.INTERACTION;
import static com.xinqi.common.core.enums.AssistantMessageTypeEnum.INTERACTIVE_VIDEO;
import static com.xinqi.common.core.enums.AssistantMessageTypeEnum.NOTICE;
import static com.xinqi.common.core.enums.AssistantMessageTypeEnum.getAssistantMessageType;

/**
 * 新奇助手消息service
 *
 * @author huangweiye
 */
@Service("chatAssistantContentService")
@RequiredArgsConstructor
public class ChatAssistantContentServiceImpl extends BaseServiceImpl<ChatAssistantContentMapper, ChatAssistantContentEntity> implements ChatAssistantContentService {

    private final ChatAssistantContentCovert chatAssistantContentCovert;

    private final ChatAssistantConfigManager chatAssistantConfigManager;

    private final ChatAssistantMQService chatAssistantMQService;

    private final ChatFriendManager chatFriendManager;


    /**
     * 批量插入新奇助手信息
     */
    @Override
    public Boolean batchInsert(List<ChatAssistantContentCreateDTO> dto) {
        // 为空给直接返回true
        if (CollectionUtil.isEmpty(dto)) {
             return Boolean.TRUE;
        }

        // 发送异步消息
        List<Long> userIds = dto.stream().map(ChatAssistantContentCreateDTO::getRecipient).collect(Collectors.toList());
        List<ChatAssistantConfigEntity> configEntities = chatAssistantConfigManager.selectByUserIds(userIds);

        // 获取用户助手集合
        LambdaQueryWrapper<ChatFriendEntity> wrapper = new LambdaQueryWrapper<>();
        wrapper.like(ChatFriendEntity::getFriendId, ChatRemindConstants.ASSISTANT);
        wrapper.in(ChatFriendEntity::getUserId, userIds);
        List<ChatFriendEntity> assistantList = chatFriendManager.list(wrapper);
        Map<Long,Long> map =  assistantList.stream().collect(Collectors.toMap(ChatFriendEntity::getUserId, ChatFriendEntity::getFriendId, (value1, value2) -> value1));

        // 老师消息
        ChatAssistantContentMessageResultDTO teacherMessage = chatAssistantContentCovert.convert(dto.get(0));
        List<Long> teacherTargetPush = new ArrayList<>();
        List<Long> teacherTargetNoPush = new ArrayList<>();

        // 助教消息
        ChatAssistantContentMessageResultDTO assistantMessage = chatAssistantContentCovert.convert(dto.get(0));
        List<Long> assistantTargetPush = new ArrayList<>();
        List<Long> assistantTargetNoPush = new ArrayList<>();

        // 学生消息
        ChatAssistantContentMessageResultDTO studentMessage = chatAssistantContentCovert.convert(dto.get(0));
        List<Long> studentTargetPush = new ArrayList<>();
        List<Long> studentTargetNoPush = new ArrayList<>();

        // 获取消息类型
        String objectName = objectName(dto.get(0).getMessageType());
        JSONObject json = JSONObject.parseObject(dto.get(0).getMessageContext());

        // 获取消息类型推送标题
        String title = json.getString("title");

        // 遍历消息内容
        dto.forEach(item -> {
            ChatAssistantConfigEntity configEntity = null;
            if (CollectionUtil.isNotEmpty(configEntities)) {
                configEntity = configEntities.stream().filter(v -> Objects.equals(item.getRecipient(), v.getUserId()))
                    .findFirst().orElse(null);
            }
            boolean flag = checkConfig(configEntity, item.getMessageType());
            if (flag) {
                JSONObject jsonObject = JSONObject.parseObject(item.getMessageContext());
                if (Objects.nonNull(configEntity) && Objects.equals(YesNoNumberEnum.YES.getCode(), configEntity.getIsDisturb())) {
                    if (Objects.equals(ClassRoleEnum.TEACHER.getCode(), jsonObject.getString("classRole"))) {
                        teacherMessage.setMessageJson(JSONUtil.long2String(jsonObject));
                        teacherTargetNoPush.add(item.getRecipient());
                    } else if (Objects.equals(ClassRoleEnum.ASSISTANT.getCode(), jsonObject.getString("classRole"))) {
                        assistantMessage.setMessageJson(JSONUtil.long2String(jsonObject));
                        assistantTargetNoPush.add(item.getRecipient());
                    } else {
                        studentMessage.setMessageJson(JSONUtil.long2String(jsonObject));
                        studentTargetNoPush.add(item.getRecipient());
                    }
                } else {
                    if (Objects.equals(ClassRoleEnum.TEACHER.getCode(), jsonObject.getString("classRole"))) {
                        teacherMessage.setMessageJson(JSONUtil.long2String(jsonObject));
                        teacherTargetPush.add(item.getRecipient());
                    } else if (Objects.equals(ClassRoleEnum.ASSISTANT.getCode(), jsonObject.getString("classRole"))) {
                        assistantMessage.setMessageJson(JSONUtil.long2String(jsonObject));
                        assistantTargetPush.add(item.getRecipient());
                    } else {
                        studentMessage.setMessageJson(JSONUtil.long2String(jsonObject));
                        studentTargetPush.add(item.getRecipient());
                    }
                }
            }
        });
        // 老师消息
        if (CollectionUtil.isNotEmpty(teacherTargetNoPush)) {
            Map<Long, List<AssistantIdDTO>> checkMap = checkAssistantGroup(map, teacherTargetNoPush);
            if (CollectionUtil.isNotEmpty(checkMap)) {
                Iterator it = checkMap.keySet().iterator();
                while(it.hasNext()) {
                    Long senderId = Long.parseLong(it.next().toString());
                    List<AssistantIdDTO> targetList = checkMap.get(senderId);
                    List<Long> targets = targetList.stream().map(AssistantIdDTO::getTargetId).collect(Collectors.toList());
                    chatAssistantMQService.sendAssistantList(teacherMessage, null, objectName, senderId, targets);
                }
            }
        }
        if (CollectionUtil.isNotEmpty(teacherTargetPush)) {
            Map<Long, List<AssistantIdDTO>> checkMap = checkAssistantGroup(map, teacherTargetPush);
            if (CollectionUtil.isNotEmpty(checkMap)) {
                Iterator it = checkMap.keySet().iterator();
                while(it.hasNext()) {
                    Long senderId = Long.parseLong(it.next().toString());
                    List<AssistantIdDTO> targetList = checkMap.get(senderId);
                    List<Long> targets = targetList.stream().map(AssistantIdDTO::getTargetId).collect(Collectors.toList());
                    chatAssistantMQService.sendAssistantList(teacherMessage, title, objectName, senderId, targets);
                }
            }
        }

        // 助教消息
        if (CollectionUtil.isNotEmpty(assistantTargetNoPush)) {
            Map<Long, List<AssistantIdDTO>> checkMap = checkAssistantGroup(map, assistantTargetNoPush);
            if (CollectionUtil.isNotEmpty(checkMap)) {
                Iterator it = checkMap.keySet().iterator();
                while(it.hasNext()) {
                    Long senderId = Long.parseLong(it.next().toString());
                    List<AssistantIdDTO> targetList = checkMap.get(senderId);
                    List<Long> targets = targetList.stream().map(AssistantIdDTO::getTargetId).collect(Collectors.toList());
                    chatAssistantMQService.sendAssistantList(assistantMessage, null, objectName, senderId, targets);
                }
            }
        }
        if (CollectionUtil.isNotEmpty(assistantTargetPush)) {
            Map<Long, List<AssistantIdDTO>> checkMap = checkAssistantGroup(map, assistantTargetPush);
            if (CollectionUtil.isNotEmpty(checkMap)) {
                Iterator it = checkMap.keySet().iterator();
                while(it.hasNext()) {
                    Long senderId = Long.parseLong(it.next().toString());
                    List<AssistantIdDTO> targetList = checkMap.get(senderId);
                    List<Long> targets = targetList.stream().map(AssistantIdDTO::getTargetId).collect(Collectors.toList());
                    chatAssistantMQService.sendAssistantList(assistantMessage, title, objectName, senderId, targets);
                }
            }
        }

        // 学生消息
        if (CollectionUtil.isNotEmpty(studentTargetNoPush)) {
            Map<Long, List<AssistantIdDTO>> checkMap = checkAssistantGroup(map, studentTargetNoPush);
            if (CollectionUtil.isNotEmpty(checkMap)) {
                Iterator it = checkMap.keySet().iterator();
                while(it.hasNext()) {
                    Long senderId = Long.parseLong(it.next().toString());
                    List<AssistantIdDTO> targetList = checkMap.get(senderId);
                    List<Long> targets = targetList.stream().map(AssistantIdDTO::getTargetId).collect(Collectors.toList());
                    chatAssistantMQService.sendAssistantList(studentMessage, null, objectName, senderId, targets);
                }
            }
        }
        if (CollectionUtil.isNotEmpty(studentTargetPush)) {
            Map<Long, List<AssistantIdDTO>> checkMap = checkAssistantGroup(map, studentTargetPush);
            if (CollectionUtil.isNotEmpty(checkMap)) {
                Iterator it = checkMap.keySet().iterator();
                while(it.hasNext()) {
                    Long senderId = Long.parseLong(it.next().toString());
                    List<AssistantIdDTO> targetList = checkMap.get(senderId);
                    List<Long> targets = targetList.stream().map(AssistantIdDTO::getTargetId).collect(Collectors.toList());
                    chatAssistantMQService.sendAssistantList(studentMessage, title, objectName, senderId, targets);
                }
            }
        }
        return Boolean.TRUE;
    }

    /**
     * 获取发送消息用户 助手ID分组信息
     */
    private Map<Long, List<AssistantIdDTO>> checkAssistantGroup(Map<Long,Long> map, List<Long> assistantTarget) {
        List<AssistantIdDTO> list = new ArrayList<>();
        assistantTarget.forEach(item -> {
            if (map.containsKey(item)) {
                AssistantIdDTO assistantId = new AssistantIdDTO();
                assistantId.setTargetId(item);
                assistantId.setSenderId(map.get(item));
                list.add(assistantId);
            }
        });
        if (CollectionUtil.isNotEmpty(list)) {
            return list.stream().collect(Collectors.groupingBy(AssistantIdDTO::getSenderId));
        } else {
            return null;
        }
    }

    /**
     * 批量更新消息助手主信息并发送信息
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean batchUpdateMain(ChatAssistantContentMainDTO dto) {
        LambdaQueryWrapper<ChatAssistantContentEntity> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(ChatAssistantContentEntity::getContentId, dto.getContentId());
        if (Objects.nonNull(dto.getTimes())) {
            wrapper.eq(ChatAssistantContentEntity::getTimes, dto.getTimes());
        }
        List<ChatAssistantContentEntity> list = this.baseMapper.selectList(wrapper);
        list.forEach(item -> {
            item.setProgressState(dto.getProgressState());
            // 保持原消息提交状态
            item.setSubmittedState(item.getSubmittedState());
            if (Objects.equals(NOTICE.getType(), item.getMessageType())) {
                NoticeMessage message = JSON.parseObject(item.getMessageContext(), NoticeMessage.class);
                message.setEndTime(dto.getEndTime());
                item.setMessageContext(JSON.toJSONString(message));
            } else if (Objects.equals(COURSEWARE.getType(), item.getMessageType())) {
                CourseWareMessage message = JSON.parseObject(item.getMessageContext(), CourseWareMessage.class);
                message.setEndTime(dto.getEndTime());
                item.setMessageContext(JSON.toJSONString(message));
            } else if (Objects.equals(INTERACTIVE_VIDEO.getType(), item.getMessageType())) {
                VideoMessage message = JSON.parseObject(item.getMessageContext(), VideoMessage.class);
                message.setEndTime(dto.getEndTime());
                item.setMessageContext(JSON.toJSONString(message));
            } else if (Objects.equals(ATTENDANCE.getType(), item.getMessageType())) {
                AttendanceMessage message = JSON.parseObject(item.getMessageContext(), AttendanceMessage.class);
                message.setEndTime(dto.getEndTime());
                item.setMessageContext(JSON.toJSONString(message));
            } else if (Objects.equals(HOMEWORK.getType(), item.getMessageType())) {
                HomeWorkMessage message = JSON.parseObject(item.getMessageContext(), HomeWorkMessage.class);
                message.setEndTime(dto.getEndTime());
                item.setMessageContext(JSON.toJSONString(message));
            } else if (Objects.equals(EXAM.getType(), item.getMessageType())) {
                EvaluationMessage message = JSON.parseObject(item.getMessageContext(), EvaluationMessage.class);
                message.setStartTime(dto.getStartTime());
                message.setEndTime(dto.getEndTime());
                item.setMessageContext(JSON.toJSONString(message));
            }
        });

        this.updateMessage(list);
         return Boolean.TRUE;
    }


    /**
     * 批量更新消息助手统计信息并发送消息
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean batchUpdateTotal(List<ChatAssistantContentTotalDTO> dto) {
        List<ChatAssistantContentEntity> entities = new ArrayList<>();
        dto.forEach(item -> {
            LambdaQueryWrapper<ChatAssistantContentEntity> wrapper = new LambdaQueryWrapper<>();
            wrapper.eq(ChatAssistantContentEntity::getContentId, item.getContentId());
            wrapper.eq(ChatAssistantContentEntity::getRecipient, item.getRecipient());
            if (Objects.nonNull(item.getTimes())) {
                wrapper.eq(ChatAssistantContentEntity::getTimes, item.getTimes());
            }
            List<ChatAssistantContentEntity> list = this.baseMapper.selectList(wrapper);
            list.forEach(msg -> {
                msg.setProgressState(item.getProgressState());
                msg.setTimes(item.getTimes());
                msg.setRecipient(item.getRecipient());
                // 更新统计数据
                JSONObject json = JSONObject.parseObject(msg.getMessageContext());
                json.put("participateNum", item.getParticipateNum());
                json.put("notParticipateNum", item.getNotParticipateNum());
                msg.setMessageContext(json.toString());
            });
            entities.addAll(list);
        });

        this.updateMessage(entities);
         return Boolean.TRUE;
    }

    /**
     * 更新消息助手信息并发送
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean batchUpdate(List<ChatAssistantContentUpdateDTO> dto) {
        List<ChatAssistantContentEntity> entities = new ArrayList<>();
        dto.forEach(item -> {
            LambdaQueryWrapper<ChatAssistantContentEntity> wrapper = new LambdaQueryWrapper<>();
            wrapper.eq(ChatAssistantContentEntity::getContentId, item.getContentId());
            if (Objects.nonNull(item.getTimes())) {
                wrapper.eq(ChatAssistantContentEntity::getTimes, item.getTimes());
            }
            if (Objects.equals(HOMEWORK.getCode(), item.getMessageType().toString())) {
                if (Objects.equals(AssistantTypeEnum.SCORE.getCode(), item.getType())) {
                    wrapper.eq(ChatAssistantContentEntity::getType, item.getType());
                }
                wrapper.eq(ChatAssistantContentEntity::getIsUpdate, YesNoNumberEnum.NO.getCode());
            }
            if (Objects.equals(EXAM.getCode(), item.getMessageType().toString())) {
                if (Objects.equals(AssistantTypeEnum.SCORE.getCode(), item.getType())) {
                    wrapper.eq(ChatAssistantContentEntity::getType, item.getType());
                }
                wrapper.eq(ChatAssistantContentEntity::getIsUpdate, YesNoNumberEnum.NO.getCode());
            }
            wrapper.eq(ChatAssistantContentEntity::getRecipient, item.getRecipient());
            List<ChatAssistantContentEntity> list = this.baseMapper.selectList(wrapper);
            list.forEach(msg -> {
                msg.setType(msg.getType());
                msg.setProgressState(item.getProgressState());
                msg.setSubmittedState(item.getSubmittedState());
                msg.setTimes(item.getTimes());
                msg.setRecipient(item.getRecipient());
                String messageContext = jsonContent(msg, item.getMessageContext());
                msg.setMessageContext(messageContext);
            });
            entities.addAll(list);
        });

        this.updateMessage(entities);
         return Boolean.TRUE;
    }

    /**
     * 修改消息为不可更新
     *
     * @param contentId 课程内容ID
     * @param times     轮次
     * @param recipient 用户ID
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean updateAssistantMessage(Long contentId, Integer times, Long recipient) {
        LambdaQueryWrapper<ChatAssistantContentEntity> wrapper = Queries.lambda();
        wrapper.eq(ChatAssistantContentEntity::getContentId, contentId);
        if (Objects.nonNull(times)) {
            wrapper.eq(ChatAssistantContentEntity::getTimes, times);
        }
        wrapper.eq(ChatAssistantContentEntity::getRecipient, recipient);
        List<ChatAssistantContentEntity> list = this.baseMapper.selectList(wrapper);
        list.forEach(item -> {
            item.setIsUpdate(YesNoNumberEnum.YES.getCode());
        });
        return this.updateBatchById(list);
    }

    /**
     * 更新消息体信息
     */
    @Override
    public Boolean update(ChatAssistantContentUpdateDTO dto) {
        ChatAssistantContentEntity entity = chatAssistantContentCovert.convert(dto);
        return updateById(entity);
    }

    private void updateMessage(List<ChatAssistantContentEntity> list) {
        for (ChatAssistantContentEntity entity : list) {
            // 获取消息内容消息体
            String objectName = objectName(entity.getMessageType());
            ChatAssistantContentMessageResultDTO message = chatAssistantContentCovert.convert(entity);
            JSONObject jsonObject = JSONObject.parseObject(entity.getMessageContext());
            message.setMessageJson(JSONUtil.long2String(jsonObject));
            chatAssistantMQService.updateAssistant(message, objectName);
        }

    }

    private String jsonContent(ChatAssistantContentEntity assistant, String item) {
        JSONObject json = JSONObject.parseObject(item);
        JSONObject oldJson = JSONObject.parseObject(assistant.getMessageContext());
        if (Objects.equals(AssistantMessageTypeEnum.HOMEWORK.getType(), assistant.getMessageType())
            && Objects.equals(AssistantTypeEnum.REPULSE.getCode(), assistant.getType())) {
            json.put("reason", oldJson.get("reason"));
        }
        if (Objects.nonNull(json.getInteger("submitStatus"))
            && Objects.nonNull(oldJson.getInteger("submitStatus"))) {
            // 不相等代表用户进行了信息提交
            if (!Objects.equals(json.getInteger("submitStatus"), oldJson.getInteger("submitStatus"))) {
                this.updateAssistantMessage(assistant.getContentId(), assistant.getTimes(), assistant.getRecipient());
            }
        }
        return json.toString();
    }

    /**
     * 获取不同课程内容消息体
     */
    private String objectName(Integer messageType) {
        String objectName = "";
        AssistantMessageTypeEnum typeEnum = getAssistantMessageType(messageType);

        // 消息类型2（1, "互动课件"，2, "资料"，3, "作业"，4, "测评"，5, "讨论"，6, "互动视频"，8, "公告"，10, "考勤"，11, "随机提问"，12, "点名提问"）
        if (typeEnum == null) {
            objectName = AssistantMesTypeEnum.QUESTIONS_NOTICE.getCode();
        } else {
            switch (typeEnum) {
                case COURSEWARE:
                    objectName = AssistantMesTypeEnum.COURSEWARE_NOTICE.getCode();
                    break;
                case DATA:
                    objectName = AssistantMesTypeEnum.MATERIAL_NOTICE.getCode();
                    break;
                case INTERACTIVE_VIDEO:
                    objectName = AssistantMesTypeEnum.VIDEO_NOTICE.getCode();
                    break;
                case ATTENDANCE:
                    objectName = AssistantMesTypeEnum.ATTENDANCE_NOTICE.getCode();
                    break;
                case NOTICE:
                    objectName = AssistantMesTypeEnum.BULLETIN_NOTICE.getCode();
                    break;
                case HOMEWORK:
                    objectName = AssistantMesTypeEnum.HOMEWORK_NOTICE.getCode();
                    break;
                case EXAM:
                    objectName = AssistantMesTypeEnum.EVALUATION_NOTICE.getCode();
                    break;
                case DISCUSS:
                    objectName = AssistantMesTypeEnum.DISCUSSION_NOTICE.getCode();
                    break;
                default:
                    // 互动课堂类型
                    objectName = AssistantMesTypeEnum.QUESTIONS_NOTICE.getCode();
                    break;
            }
        }
        return objectName;
    }

    /**
     * 新奇提醒通知设置，是否接收此类提醒
     *
     * @param configEntity
     * @param type
     * @return
     */
    private boolean checkConfig(ChatAssistantConfigEntity configEntity, Integer type) {
        // 判断是否是互动课堂 11抢答 12随机
        if (Objects.equals(11, type) || Objects.equals(12, type)) {
            type = INTERACTION.getType();
        }
        if (Objects.isNull(configEntity)) {
             return Boolean.TRUE;
        }
        if (Objects.equals(COURSEWARE.getType(), type)) {
            return Objects.equals(YesNoNumberEnum.YES.getCode(), configEntity.getCourseware());
        } else if (Objects.equals(DATA.getType(), type)) {
            return Objects.equals(YesNoNumberEnum.YES.getCode(), configEntity.getResource());
        } else if (Objects.equals(HOMEWORK.getType(), type)) {
            return Objects.equals(YesNoNumberEnum.YES.getCode(), configEntity.getTask());
        } else if (Objects.equals(EXAM.getType(), type)) {
            return Objects.equals(YesNoNumberEnum.YES.getCode(), configEntity.getTest());
        } else if (Objects.equals(DISCUSS.getType(), type)) {
            return Objects.equals(YesNoNumberEnum.YES.getCode(), configEntity.getTopic());
        } else if (Objects.equals(INTERACTIVE_VIDEO.getType(), type)) {
            return Objects.equals(YesNoNumberEnum.YES.getCode(), configEntity.getVideo());
        } else if (Objects.equals(NOTICE.getType(), type)) {
            return Objects.equals(YesNoNumberEnum.YES.getCode(), configEntity.getNotice());
        } else if (Objects.equals(INTERACTION.getType(), type)) {
            return Objects.equals(YesNoNumberEnum.YES.getCode(), configEntity.getInteraction());
        } else if (Objects.equals(ATTENDANCE.getType(), type)) {
            return Objects.equals(YesNoNumberEnum.YES.getCode(), configEntity.getAttendance());
        }
         return Boolean.TRUE;
    }
}
